let arr = [1, 2, 3, 4]
let loopTimer//外层定时
let Timer=[]//内层延迟
function setTimeOut (arr,endTimeout) {
  let tempArr=[]
  for (let i = 0; i < arr.length; i++) {
    tempArr.push(setTimeout(() => {
      // fn(i,arr)
      console.log(arr[i])
    }, 2000 * i))
  }
  Timer=tempArr
}
function setInterVal (fn, arr) {
  fn(arr)
  loopTimer = setInterval(() => { fn(arr) }, arr.length * 2000)
}
setInterVal(setTimeOut,arr)
clearInterval(loopTimer)
Timer.forEach((item)=>{
  clearTimeout(item)
})

// let a = setTimeout(() => {
//   console.log(123)
// }, 5000);
// clearTimeout(a)